package com.alasbusy.alasbusyapp.activity.twoactivity;

import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.alasbusy.alasbusyapp.R;
import com.alasbusy.alasbusyapp.adapter.HomeAdapter;
import com.alasbusy.alasbusyapp.adapter.HtmlCssAdapter;
import com.alasbusy.alasbusyapp.base.BaseActivity;
import com.alasbusy.alasbusyapp.bean.HomeBean;
import com.zhy.android.percent.support.PercentLinearLayout;

import java.util.ArrayList;
import java.util.List;

public class HtmlCssActivity extends BaseActivity {
    private RecyclerView recyclerview;
    private SwipeRefreshLayout swiplayout;
    private LinearLayoutManager linearLayoutManager;
    private HtmlCssAdapter htmlCssAdapter;
    public int Count = 0;
    public int nowpage = 0;

    public List<HomeBean> list = new ArrayList<>();
    private String type;

    @Override
    protected void initView() {
        PercentLinearLayout html_title = findViewById(R.id.html_title);
        setTop(html_title);
        getVisibility(true,this);
        type = getIntent().getStringExtra("type");
        if(type.equals("html")) {
            getTitle("html/css");
        }else if(type.equals("android")){
            getTitle("android");
        }else if(type.equals("php")){
            getTitle("php相关");
        }else if(type.equals("linux")){
            getTitle("linux系统");
        }else if(type.equals("web")){
            getTitle("web服务");
        }
        swiplayout = findViewById(R.id.html_swiplayout);
        recyclerview = findViewById(R.id.html_recyclerview);
        swiplayout.setColorSchemeResources(R.color.color_re, R.color.color_re3, R.color.tr4, R.color.color_re2);
        linearLayoutManager = new LinearLayoutManager(this);
        recyclerview.setLayoutManager(linearLayoutManager);
        recyclerview.setItemAnimator(new DefaultItemAnimator());
        //recyclerview.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        htmlCssAdapter = new HtmlCssAdapter(this);
        recyclerview.setAdapter(htmlCssAdapter);

    }

    @Override
    protected void initData() {
        list.clear();
        if(type.equals("html")) {
            setHtmlData(0);
            onHtmlRefresh();
        }else if(type.equals("android")){
            setAndroidData(0);
            onAndroidRefresh();
        }else if(type.equals("php")){
            setPHPData(0);
            onPHPRefresh();
        }else if(type.equals("linux")){
            setLinuxData(0);
            onLinuxRefresh();
        }else if(type.equals("web")){
            setWebData(0);
            onWebRefresh();
        }
    }

    public void setHtmlData(int page) {
        //获取本地数据库里的数据
        /*guestRegistration = GuestRegistrationManager.getInstance().getGuestRegistration(page);
        if (guestRegistration != null && guestRegistration.size() > 0) {
            visitorReservationAdapter.setList(guestRegistration);
            fragment_visitor_reser.setAdapter(visitorReservationAdapter);
            visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.LOADING_NO);
            fragment_visitor_reser.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        }else {
            fragment_visitor_reser.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }*/
        HomeBean homeBean = new HomeBean();
        HomeBean.DataBean dataBean = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean = new HomeBean.DataBean.ItemdataBean();
        itemdataBean.setTitle("iframe调用父页面的元素，通过点击子页面元素实现菜单效果");
        itemdataBean.setContent("需求：easyUI应该都熟悉，就是点击左边菜单栏，上面出现tab标签和子页面，这个也类似，不过还需要一个功能，就是点");
        itemdataBean.setCount("59");
        itemdataBean.setName("kyc");
        itemdataBean.setTime("2018-5-11");
        dataBean.setItemdata(itemdataBean);
        homeBean.setData(dataBean);

        HomeBean homeBean1 = new HomeBean();
        HomeBean.DataBean dataBean1 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean1 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean1.setTitle("CSS秘密花园：斜切角");
        itemdataBean1.setContent("《CSS Secrets》是@Lea Verou最新著作，这本书讲解了有关于CSS中一些小秘密。是一本CSSer值得一读的一本书，经");
        itemdataBean1.setCount("95");
        itemdataBean1.setName("kyc");
        itemdataBean1.setTime("2018-5-11");
        dataBean1.setItemdata(itemdataBean1);
        homeBean1.setData(dataBean1);

        HomeBean homeBean2 = new HomeBean();
        HomeBean.DataBean dataBean2 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean2 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean2.setTitle("jQuery无法获取隐藏元素的宽高");
        itemdataBean2.setContent("用jQuery写一个通过点击左右图标来翻阅图片的小插件，写好后测试可以正常运行，但是放到Tab中后发现只有第一个Tab");
        itemdataBean2.setCount("37");
        itemdataBean2.setName("kyc");
        itemdataBean2.setTime("2018-5-11");
        dataBean2.setItemdata(itemdataBean2);
        homeBean2.setData(dataBean2);

        list.add(homeBean);
        list.add(homeBean1);
        list.add(homeBean2);
        htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
        htmlCssAdapter.setList(list);
    }

    public void setAndroidData(int page) {
        //获取本地数据库里的数据
        /*guestRegistration = GuestRegistrationManager.getInstance().getGuestRegistration(page);
        if (guestRegistration != null && guestRegistration.size() > 0) {
            visitorReservationAdapter.setList(guestRegistration);
            fragment_visitor_reser.setAdapter(visitorReservationAdapter);
            visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.LOADING_NO);
            fragment_visitor_reser.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        }else {
            fragment_visitor_reser.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }*/
        HomeBean homeBean = new HomeBean();
        HomeBean.DataBean dataBean = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean = new HomeBean.DataBean.ItemdataBean();
        itemdataBean.setTitle("Android中View的事件分发机制");
        itemdataBean.setContent("简介前面我们介绍过View的工作原理以及如何自绘一个View，这些都是View在屏幕上展现的一些故事，今天我们继续来谈");
        itemdataBean.setCount("34");
        itemdataBean.setName("紫云新");
        itemdataBean.setTime("2018-5-20");
        dataBean.setItemdata(itemdataBean);
        homeBean.setData(dataBean);

        HomeBean homeBean1 = new HomeBean();
        HomeBean.DataBean dataBean1 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean1 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean1.setTitle("Android 调用第三方jar包和so库文件(3)");
        itemdataBean1.setContent("本系列是分为三步走1.生成so库文件 打开地址2.生成jar包 打开地址3.调用自己生成的so库和jar包(本篇)本篇是第三部分");
        itemdataBean1.setCount("45");
        itemdataBean1.setName("kyc");
        itemdataBean1.setTime("2018-5-16");
        dataBean1.setItemdata(itemdataBean1);
        homeBean1.setData(dataBean1);

        HomeBean homeBean2 = new HomeBean();
        HomeBean.DataBean dataBean2 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean2 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean2.setTitle("碎片的使用一(fragment切换)");
        itemdataBean2.setContent("在开发中，我们经常要用到碎片，碎片与活动特别像，但却不是。在我们平常看到的平板与手机之间的app会清晰地发现两");
        itemdataBean2.setCount("27");
        itemdataBean2.setName("程序的灵魂终结者");
        itemdataBean2.setTime("2018-5-21");
        dataBean2.setItemdata(itemdataBean2);
        homeBean2.setData(dataBean2);

        list.add(homeBean);
        list.add(homeBean1);
        list.add(homeBean2);
        htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
        htmlCssAdapter.setList(list);
    }

    public void setPHPData(int page) {
        //获取本地数据库里的数据
        /*guestRegistration = GuestRegistrationManager.getInstance().getGuestRegistration(page);
        if (guestRegistration != null && guestRegistration.size() > 0) {
            visitorReservationAdapter.setList(guestRegistration);
            fragment_visitor_reser.setAdapter(visitorReservationAdapter);
            visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.LOADING_NO);
            fragment_visitor_reser.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        }else {
            fragment_visitor_reser.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }*/
        HomeBean homeBean = new HomeBean();
        HomeBean.DataBean dataBean = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean = new HomeBean.DataBean.ItemdataBean();
        itemdataBean.setTitle("phpcms 双模板模式");
        itemdataBean.setContent("现在随着智能手机的兴起，我们网站开发移动端版本也显得越来重要了，但是现在phpcms还没有开发手机版，下面我们就");
        itemdataBean.setCount("17");
        itemdataBean.setName("33025624");
        itemdataBean.setTime("2018-5-10");
        dataBean.setItemdata(itemdataBean);
        homeBean.setData(dataBean);

        HomeBean homeBean1 = new HomeBean();
        HomeBean.DataBean dataBean1 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean1 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean1.setTitle("CSS秘密花园：斜切角");
        itemdataBean1.setContent("《CSS Secrets》是@Lea Verou最新著作，这本书讲解了有关于CSS中一些小秘密。是一本CSSer值得一读的一本书，经");
        itemdataBean1.setCount("95");
        itemdataBean1.setName("kyc");
        itemdataBean1.setTime("2018-5-11");
        dataBean1.setItemdata(itemdataBean1);
        homeBean1.setData(dataBean1);

        HomeBean homeBean2 = new HomeBean();
        HomeBean.DataBean dataBean2 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean2 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean2.setTitle("jQuery无法获取隐藏元素的宽高");
        itemdataBean2.setContent("用jQuery写一个通过点击左右图标来翻阅图片的小插件，写好后测试可以正常运行，但是放到Tab中后发现只有第一个Tab");
        itemdataBean2.setCount("37");
        itemdataBean2.setName("kyc");
        itemdataBean2.setTime("2018-5-11");
        dataBean2.setItemdata(itemdataBean2);
        homeBean2.setData(dataBean2);

        list.add(homeBean);
        list.add(homeBean1);
        list.add(homeBean2);
        htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
        htmlCssAdapter.setList(list);
    }

    public void setLinuxData(int page) {
        //获取本地数据库里的数据
        /*guestRegistration = GuestRegistrationManager.getInstance().getGuestRegistration(page);
        if (guestRegistration != null && guestRegistration.size() > 0) {
            visitorReservationAdapter.setList(guestRegistration);
            fragment_visitor_reser.setAdapter(visitorReservationAdapter);
            visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.LOADING_NO);
            fragment_visitor_reser.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        }else {
            fragment_visitor_reser.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }*/
        HomeBean homeBean = new HomeBean();
        HomeBean.DataBean dataBean = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean = new HomeBean.DataBean.ItemdataBean();
        itemdataBean.setTitle("iframe调用父页面的元素，通过点击子页面元素实现菜单效果");
        itemdataBean.setContent("需求：easyUI应该都熟悉，就是点击左边菜单栏，上面出现tab标签和子页面，这个也类似，不过还需要一个功能，就是点");
        itemdataBean.setCount("59");
        itemdataBean.setName("kyc");
        itemdataBean.setTime("2018-5-11");
        dataBean.setItemdata(itemdataBean);
        homeBean.setData(dataBean);

        HomeBean homeBean1 = new HomeBean();
        HomeBean.DataBean dataBean1 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean1 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean1.setTitle("CSS秘密花园：斜切角");
        itemdataBean1.setContent("《CSS Secrets》是@Lea Verou最新著作，这本书讲解了有关于CSS中一些小秘密。是一本CSSer值得一读的一本书，经");
        itemdataBean1.setCount("95");
        itemdataBean1.setName("kyc");
        itemdataBean1.setTime("2018-5-11");
        dataBean1.setItemdata(itemdataBean1);
        homeBean1.setData(dataBean1);

        HomeBean homeBean2 = new HomeBean();
        HomeBean.DataBean dataBean2 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean2 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean2.setTitle("jQuery无法获取隐藏元素的宽高");
        itemdataBean2.setContent("用jQuery写一个通过点击左右图标来翻阅图片的小插件，写好后测试可以正常运行，但是放到Tab中后发现只有第一个Tab");
        itemdataBean2.setCount("37");
        itemdataBean2.setName("kyc");
        itemdataBean2.setTime("2018-5-11");
        dataBean2.setItemdata(itemdataBean2);
        homeBean2.setData(dataBean2);

        list.add(homeBean);
        list.add(homeBean1);
        list.add(homeBean2);
        htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
        htmlCssAdapter.setList(list);
    }

    public void setWebData(int page) {
        //获取本地数据库里的数据
        /*guestRegistration = GuestRegistrationManager.getInstance().getGuestRegistration(page);
        if (guestRegistration != null && guestRegistration.size() > 0) {
            visitorReservationAdapter.setList(guestRegistration);
            fragment_visitor_reser.setAdapter(visitorReservationAdapter);
            visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.LOADING_NO);
            fragment_visitor_reser.setVisibility(View.VISIBLE);
            no_data.setVisibility(View.GONE);
        }else {
            fragment_visitor_reser.setVisibility(View.GONE);
            no_data.setVisibility(View.VISIBLE);
        }*/
        HomeBean homeBean = new HomeBean();
        HomeBean.DataBean dataBean = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean = new HomeBean.DataBean.ItemdataBean();
        itemdataBean.setTitle("iframe调用父页面的元素，通过点击子页面元素实现菜单效果");
        itemdataBean.setContent("需求：easyUI应该都熟悉，就是点击左边菜单栏，上面出现tab标签和子页面，这个也类似，不过还需要一个功能，就是点");
        itemdataBean.setCount("59");
        itemdataBean.setName("kyc");
        itemdataBean.setTime("2018-5-11");
        dataBean.setItemdata(itemdataBean);
        homeBean.setData(dataBean);

        HomeBean homeBean1 = new HomeBean();
        HomeBean.DataBean dataBean1 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean1 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean1.setTitle("CSS秘密花园：斜切角");
        itemdataBean1.setContent("《CSS Secrets》是@Lea Verou最新著作，这本书讲解了有关于CSS中一些小秘密。是一本CSSer值得一读的一本书，经");
        itemdataBean1.setCount("95");
        itemdataBean1.setName("kyc");
        itemdataBean1.setTime("2018-5-11");
        dataBean1.setItemdata(itemdataBean1);
        homeBean1.setData(dataBean1);

        HomeBean homeBean2 = new HomeBean();
        HomeBean.DataBean dataBean2 = new HomeBean.DataBean();
        HomeBean.DataBean.ItemdataBean itemdataBean2 = new HomeBean.DataBean.ItemdataBean();
        itemdataBean2.setTitle("jQuery无法获取隐藏元素的宽高");
        itemdataBean2.setContent("用jQuery写一个通过点击左右图标来翻阅图片的小插件，写好后测试可以正常运行，但是放到Tab中后发现只有第一个Tab");
        itemdataBean2.setCount("37");
        itemdataBean2.setName("kyc");
        itemdataBean2.setTime("2018-5-11");
        dataBean2.setItemdata(itemdataBean2);
        homeBean2.setData(dataBean2);

        list.add(homeBean);
        list.add(homeBean1);
        list.add(homeBean2);
        htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
        htmlCssAdapter.setList(list);
    }

    @Override
    protected void initListener() {

    }

    @Override
    public int getLayout() {
        return R.layout.activity_html_css;
    }

    private void onHtmlRefresh() {
        swiplayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
                swiplayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 下拉刷新  更新完后调用该方法结束刷新
                        if (nowpage == 0) {
                            setHtmlData(nowpage);
                        } else {
                            nowpage = nowpage - 1;
                            setHtmlData(nowpage);
                        }
                        htmlCssAdapter.setList(list);
                        htmlCssAdapter.notifyDataSetChanged();
                        swiplayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
            public int lastVisibleItem;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == htmlCssAdapter.getItemCount()) {
                    htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_MORE);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //swipeLayout.setLoading(false);
                            // 上拉加载  更新完后调用该方法结束刷新
                            if (nowpage == Count) {
                                setHtmlData(Count);
                            } else {
                                nowpage = nowpage + 1;
                                setHtmlData(nowpage);
                            }
                            htmlCssAdapter.setList(list);
                            recyclerview.smoothScrollToPosition(0);
                            htmlCssAdapter.notifyDataSetChanged();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.PULLUP_LOAD_MORE);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }

    private void onAndroidRefresh() {
        swiplayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
                swiplayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 下拉刷新  更新完后调用该方法结束刷新
                        if (nowpage == 0) {
                            setAndroidData(nowpage);
                        } else {
                            nowpage = nowpage - 1;
                            setAndroidData(nowpage);
                        }
                        htmlCssAdapter.setList(list);
                        htmlCssAdapter.notifyDataSetChanged();
                        swiplayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
            public int lastVisibleItem;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == htmlCssAdapter.getItemCount()) {
                    htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_MORE);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //swipeLayout.setLoading(false);
                            // 上拉加载  更新完后调用该方法结束刷新
                            if (nowpage == Count) {
                                setAndroidData(Count);
                            } else {
                                nowpage = nowpage + 1;
                                setAndroidData(nowpage);
                            }
                            htmlCssAdapter.setList(list);
                            recyclerview.smoothScrollToPosition(0);
                            htmlCssAdapter.notifyDataSetChanged();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.PULLUP_LOAD_MORE);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }

    private void onPHPRefresh() {
        swiplayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
                swiplayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 下拉刷新  更新完后调用该方法结束刷新
                        if (nowpage == 0) {
                            setPHPData(nowpage);
                        } else {
                            nowpage = nowpage - 1;
                            setPHPData(nowpage);
                        }
                        htmlCssAdapter.setList(list);
                        htmlCssAdapter.notifyDataSetChanged();
                        swiplayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
            public int lastVisibleItem;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == htmlCssAdapter.getItemCount()) {
                    htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_MORE);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //swipeLayout.setLoading(false);
                            // 上拉加载  更新完后调用该方法结束刷新
                            if (nowpage == Count) {
                                setPHPData(Count);
                            } else {
                                nowpage = nowpage + 1;
                                setPHPData(nowpage);
                            }
                            htmlCssAdapter.setList(list);
                            recyclerview.smoothScrollToPosition(0);
                            htmlCssAdapter.notifyDataSetChanged();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.PULLUP_LOAD_MORE);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }

    private void onLinuxRefresh() {
        swiplayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
                swiplayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 下拉刷新  更新完后调用该方法结束刷新
                        if (nowpage == 0) {
                            setLinuxData(nowpage);
                        } else {
                            nowpage = nowpage - 1;
                            setLinuxData(nowpage);
                        }
                        htmlCssAdapter.setList(list);
                        htmlCssAdapter.notifyDataSetChanged();
                        swiplayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
            public int lastVisibleItem;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == htmlCssAdapter.getItemCount()) {
                    htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_MORE);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //swipeLayout.setLoading(false);
                            // 上拉加载  更新完后调用该方法结束刷新
                            if (nowpage == Count) {
                                setLinuxData(Count);
                            } else {
                                nowpage = nowpage + 1;
                                setLinuxData(nowpage);
                            }
                            htmlCssAdapter.setList(list);
                            recyclerview.smoothScrollToPosition(0);
                            htmlCssAdapter.notifyDataSetChanged();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.PULLUP_LOAD_MORE);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }

    private void onWebRefresh() {
        swiplayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_NO);
                swiplayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 下拉刷新  更新完后调用该方法结束刷新
                        if (nowpage == 0) {
                            setWebData(nowpage);
                        } else {
                            nowpage = nowpage - 1;
                            setWebData(nowpage);
                        }
                        htmlCssAdapter.setList(list);
                        htmlCssAdapter.notifyDataSetChanged();
                        swiplayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

        recyclerview.setOnScrollListener(new RecyclerView.OnScrollListener() {
            public int lastVisibleItem;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 1 == htmlCssAdapter.getItemCount()) {
                    htmlCssAdapter.changeMoreStatus(HomeAdapter.LOADING_MORE);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            //swipeLayout.setLoading(false);
                            // 上拉加载  更新完后调用该方法结束刷新
                            if (nowpage == Count) {
                                setWebData(Count);
                            } else {
                                nowpage = nowpage + 1;
                                setWebData(nowpage);
                            }
                            htmlCssAdapter.setList(list);
                            recyclerview.smoothScrollToPosition(0);
                            htmlCssAdapter.notifyDataSetChanged();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //visitorReservationAdapter.changeMoreStatus(SystemDeleteUserAdapter.PULLUP_LOAD_MORE);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }
}
